from rest_framework import serializers

from apps.question.models import Question, Label, Reply
from apps.users.models import User


class QuestionModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Question
        fields = "__all__"

    # def create(self, validated_data):
    #     return validated_data.get('id')


class LabelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Label
        fields = ('label_name',)


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'username', 'avatar')


class SubSerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = Reply
        fields = "__all__"


class CommentQuestion(serializers.ModelSerializer):
    subs = SubSerializer(many=True)
    user = UserSerializer()

    class Meta:
        model = Reply
        fields = "__all__"


class AnswerQuestion(serializers.ModelSerializer):
    subs = SubSerializer(many=True)
    user = UserSerializer()

    class Meta:
        model = Reply
        fields = "__all__"


class Question(serializers.ModelSerializer):
    labels = LabelSerializer(many=True)
    comment_question = CommentQuestion(many=True)
    answer_question = AnswerQuestion(many=True)

    class Meta:
        model = Question
        fields = '__all__'





